package com.cwj.text;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class writeData {
    public static void main(String[] args) throws IOException {
        System.out.println("请输入要转化的文字：");
        String str=new String();
        Scanner in=new Scanner(System.in);
        str=in.next();
        byte[]nums=str.getBytes("GB2312");
        String ss=null;
        try(FileWriter out=new FileWriter("C:\\Users\\抑~风\\Desktop\\机内码.txt")){
            for(int i=0;i<nums.length;i+=1){
                ss=Integer.toHexString(nums[i]&0xff);
                System.out.println(ss);
                if(ss.length()<2){
                    out.write("0");
                }
                out.write(ss);
                if((i+1)%16==0){
                    out.write("\n");
                }
                else if((i+1)%8==0){
                    out.write("  ");
                }else if((i+1)%2==0){
                    out.write(" ");
                }

            }
        }
    }
}
